/*******************************************************************************

[Last updated: June 4th, 2024]

This script is the last one in the runny sequence for the Endline data analysis

The script follows a similar structure to the admin analysis, in which each 
table in the manuscript corresponds to a set of code that delineates the top, 
middle, and bottom of the table.

*******************************************************************************/

	
	
	
	
	
	
	
	
	* Table 1
	table_start_horizontal endline_interpretation_combine.txt ///
	"Considering Alternative Interpretations" 275 5 CM Sit-D SE p-value q-value r r r p{1.1cm} p{1.1cm}
	midrule
			
			file write table "\\"
			file write table "\multicolumn{6}{c}{\textbf{Panel A: Alternative Interpretations of a Subject's Actions}}  \\"
			midrule
			write_horizontal q_H_total_interpretations 	"Total explanations" 										CmCoSePvQv
			write_horizontal q_H_dummy_twocategories 	"Explanations from multiple categories" 					CmCoSePvQv
			write_horizontal q_H_dummy_A 				"At least one explanation - assistance category" 			CmCoSePvQv
			write_horizontal q_H_dummy_E 				"At least one explanation - enforcement category" 			CmCoSePvQv
			write_horizontal q_H_dummy_NA 				"At least one explanation - other category" 				CmCoSePvQv
			file write table "\\"

			file write table "\multicolumn{6}{c}{\textbf{Panel B: Processing Information and Forming Interpretations}} \\"
			midrule
			write_horizontal q_H_zall_features_unsel	"Alternative Features Index (both tasks)" 					hCmCoSePvQv
			write_horizontal q_H_zall_features_sel		"Confirming Features Index (both tasks)" 					hCmCoSePvQv
			write_horizontal q_H_overall 				"Criminal Interpretations Index (both tasks)" 				hCmCoSePvQv
			write_horizontal q_H_t_overall 				"Decision Time Index (both tasks)" 							hCmCoSePvQv 
			write_horizontal q_H_proccessing_log_time 	"Processing Time Index (officer-timed task)" 				hCmCoSePvQv
			file write table "\\"

			file write table "\multicolumn{6}{c}{\textbf{Panel C: Use of Force in Dynamic Situations}} \\"
			midrule
			write_horizontal q_H_appropriate_action2 	"Change – perceived threat \& force assessment (index)" 	hCmCoSePvQv
			write_horizontal q_H_z_appropriate 			"Appropriate actions (index)" 								hCmCoSePvQv
			write_horizontal q_H_z_nonappropriate 		"Inappropriate actions (index)" 							hCmCoSePvQv

			
		table_end "$endline_interpretation_combine" endline_interpretation_combine 
		
	* Table 2: Panel A
	table_start_horizontal endline_communication.txt ///
	"Movement and Communication in the FOS"  275 4 Sit-D SE	p-value q-value	r r p{1.1cm} p{1.1cm}
	midrule
		write_horizontal q_H_communicate "Did the officer communicate with the person? (index)" 					CoSePvQv
		write_horizontal q_H_verbalize "Did the officer give verbal direction/ commands to the person? (index)" 	CoSePvQv
		write_horizontal q_H_radio "Did the officer radio dispatch? (index)" 										CoSePvQv
		write_horizontal q_H_freeze "Did the officer freeze during the scenario? (index)" 							CoSePvQv
		write_horizontal q_H_moving_cover "Did the officer kneel or move to cover/ concealment? (index)" 			CoSePvQv
	table_end "$endline_communication" endline_communication
	
	* Table 2: Panel B
	mat A = q_H_FOS_treat
	mat B = q_H_FOS_risk
	mat C = q_H_shooting_FOS
	
	table_start_FOS endline_firing_threat_combine.txt ///
	"Shooting in the FOS"
	midrule
		write_i A B C "Shooting in the FOS"
	table_end "$endline_shooting_fos_combine" endline_firing_threat_combine
	

* Appendix
	
	* Appendix B5: Knowledge
	table_start_horizontal endline_knowledge.txt ///
	"Knowledge of Training Concepts" 200 5 CM Sit-D SE p-value q-value r r r p{1.1cm} p{1.1cm}
	midrule
		write_horizontal q_H_knowledge "Knowledge Of Sit-D Concepts Index" 	RcCoSePvQv
		midrule
		write_horizontal q_H_q3_score "Confirmation Trap" 					CmCoSePvRq
		write_horizontal q_H_q4_score "Personalization" 					CmCoSePvRq
		write_horizontal q_H_q5_score "Overgeneralization" 					CmCoSePvRq
		write_horizontal q_H_q6_score "Catastrophizing" 					CmCoSePvRq
		write_horizontal q_H_q8_score "Thinking Tactic Model"		 		CmCoSePvRq
	table_end "$endline_knowledge" endline_knowledge
	
	* Appendix B7: Stress and Emotion
	table_start_horizontal endline_stress_emotion_detailed.txt ///
	"Stress and Emotion Regulation" 250 5 CM Sit-D SE p-value q-value r r r p{1.1cm} p{1.1cm}
	midrule
			file write table "\\"
			file write table "\multicolumn{6}{c}{\textbf{Panel A: Coping with Stress}}  \\"
			midrule
			
			write_horizontal q_H_stress 		"Coping With Stress Index"  RcCoSePvQv
			midrule
			write_horizontal q_H_q17_1_score 	"In stressful situations, how often do you cope with the stress by engaging in deep breathing?" CmCoSePvRq
			write_horizontal q_H_q17_2_score 	"In stressful situations, how often do you cope with the stress by taking a break from the situation if it is possible to do so?"  CmCoSePvRq
			write_horizontal q_H_q17_3_score 	"In stressful situations, how often do you cope with the stress by seeking support from others if it is possible to do so?" CmCoSePvRq
			file write table "\\"

			file write table "\multicolumn{6}{c}{\textbf{Panel B: Emotion Regulation}} \\"
			midrule
			write_horizontal q_H_emotion 		"Emotion Regulation Index" 																				RcCoSePvQv
			midrule
			write_horizontal q_H_q15_1_score 	"I could be experiencing some emotion and not be conscious of it until some time later." 					CmCoSePvRq
			write_horizontal q_H_q15_2_score 	"I control my emotions by changing the way I think about the situation I'm in." 							CmCoSePvRq
			write_horizontal q_H_q15_3_score 	"I control my emotions by not expressing them." 															CmCoSePvRq
		table_end "$endline_stress_emotion_detailed" endline_stress_emotion_detailed

	* Apendix B6: Knowledge use of force
	table_start_horizontal endline_knowledge_of_force_short.txt ///
	"Knowledge of Use of Force Policy" 300 4 Sit-D SE p-value q-value r r p{1.1cm} p{1.1cm}
		midrule
		write_horizontal q_H_assailants_correct "Correct assailant level in policy (index)" CoSePvQv
		write_horizontal q_H_force_correct "Correct force level in policy (index)" CoSePvQv
		write_horizontal q_H_z_q50_level "Characterization of assailant who is a direct threat (z-score)" CoSePvQv
	table_end "$endline_knowledge_of_force_short" endline_knowledge_of_force_short
	
	* Appendix B9: Personalization
	table_start_horizontal endline_personalization.txt ///
	"Personalization" 175 5 CM Sit-D SE p-value q-value r r r p{1.1cm} p{1.1cm}
	midrule
		write_horizontal q_H_personalization "Personalization Index" 															  RcCoSePvQv
		midrule
		write_horizontal q_H_q20_score "While an officer performs a traffic stop, a bystander starts filming."  				  CmCoSePvRq
		write_horizontal q_H_q71_score "While an officer interacts with a group of people, they demand to know his badge number."  CmCoSePvRq
		write_horizontal q_H_q75_score "A person refuses to provide ID to an officer."  										  CmCoSePvRq
		write_horizontal q_H_q77_score "A person swears at an officer who initiates a search."  								  CmCoSePvRq
		write_horizontal q_H_q80_score "A large crowd of protestors are swearing at an officer and chanting 'defund the police'." CmCoSePvRq
	table_end "$endline_personalization" endline_personalization
	
	*Appendix B8: Confidence
	table_start_horizontal endline_confidence.txt ///
	"Confidence in Policing" 200 5 CM Sit-D SE p-value q-value r r r p{1.1cm} p{1.1cm}					
	midrule
		write_horizontal q_H_policing "Confidence Index" RcCoSePvQv
		midrule
		write_horizontal q_H_q13_1_score "How confident are you in your ability to effectively respond to a domestic disturbance call?"   CmCoSePvRq
		write_horizontal q_H_q13_2_score "How confident are you in your ability to effectively respond to a robbery in progress call?"  CmCoSePvRq
		write_horizontal q_H_q13_3_score "How confident are you in your ability to effectively respond to a shots fired call?"  CmCoSePvRq
		write_horizontal q_H_q13_4_score "How confident are you in your ability to do your job effectively during a protest about policing?"  CmCoSePvRq
		write_horizontal q_H_q13_5_score "How confident are you in your ability to effectively carry out all aspects of your duty as a police officer?"  CmCoSePvRq
	table_end "$endline_confidence" endline_confidence

	* Appendix B10: Additional outcomes 
	table_start_horizontal endline_post_outcomes.txt ///
	"Post-Force Options Simulator Outcomes" 150 4 Sit-D SE p-value q-value r r p{1.1cm} p{1.1cm}
	midrule
		write_horizontal q_H_item			"Recall Index"		 	CoSePvQv
		write_horizontal q_H_clarity 		"Articulation Index"	CoSePvQv
	table_end "$endline_post_outcomes" endline_post_outcomes
	
	* Appendix B11: Combined - LASSO
	table_start_horizontal endline_all_LASSO.txt ///
	"Endline Assessment Outcomes with LASSO-selected Covariates" 300 6 CM Sit-D SE p-value q-value N r r r p{1.2cm} p{1.1cm} r
	midrule
		write_horizontal q_L_knowledge 				"Knowledge Of Sit-D Concepts Index" 										RcCoSePvQvN
		write_horizontal q_L_assailants_correct 	"Correct assailant level in policy (index)"									RcCoSePvQvN
		write_horizontal q_L_force_correct 			"Correct force level in policy (index)" 									RcCoSePvQvN
		write_horizontal q_L_z_q50_level 			"Characterization of assailant who is a direct threat (z-score)" 			RcCoSePvQvN
		midrule
		write_horizontal q_L_total_interpretations "Total explanations" 														CmCoSePvQvN
		write_horizontal q_L_dummy_twocategories 	"Explanations from multiple categories" 									CmCoSePvQvN
		write_horizontal q_L_dummy_A 				"At least one explanation - assistance category" 							CmCoSePvQvN
		write_horizontal q_L_dummy_E 				"At least one explanation - enforcement category" 							CmCoSePvQvN
		write_horizontal q_L_dummy_NA 				"At least one explanation - other category" 								CmCoSePvQvN
		write_horizontal q_L_zall_features_unsel	"Alternative Features Index (both tasks)" 									RcCoSePvQvN
		write_horizontal q_L_zall_features_sel		"Confirming Features Index (both tasks)" 									RcCoSePvQvN
		write_horizontal q_L_overall 				"Criminal Interpretations Index (both tasks)" 								RcCoSePvQvN
		write_horizontal q_L_t_overall 				"Decision Time Index (both tasks)"  										RcCoSePvQvN
		write_horizontal q_L_proccessing_log_time 	"Processing Time Index (officer-timed task)"								RcCoSePvQvN
		write_horizontal q_L_appropriate_action2 	"Change - perceived threat \& force assessment (index)"						RcCoSePvQvN
		write_horizontal q_L_z_appropriate 			"Appropriate actions (index)" 												RcCoSePvQvN
		write_horizontal q_L_z_nonappropriate 		"Inappropriate actions (index)"												RcCoSePvQvN
		write_horizontal q_L_personalization 		"Personalization Index" 													RcCoSePvQvN
		write_horizontal q_L_stress					"Coping With Stress Index" 													RcCoSePvQvN
		write_horizontal q_L_emotion 				"Emotion Regulation Index"													RcCoSePvQvN
		write_horizontal q_L_policing 				"Confidence Index"															RcCoSePvQvN
		midrule
		write_horizontal q_L_communicate 			"Did the officer communicate with the person? (index)" 						RcCoSePvQvN
		write_horizontal q_L_verbalize 				"Did the officer give verbal direction/ commands to the person? (index)" 	RcCoSePvQvN
		write_horizontal q_L_radio 					"Did the officer radio dispatch? (index)" 									RcCoSePvQvN
		write_horizontal q_L_freeze 				"Did the officer freeze during the scenario? (index)"						RcCoSePvQvN
		write_horizontal q_L_moving_cover 			"Did the officer kneel or move to cover/ concealment? (index)" 				RcCoSePvQvN
		write_horizontal q_L_shooting_FOS 			"Shooting in the FOS (interaction term)"									RcCoSePvQvN
		write_horizontal q_L_item					"Recall Index" 																RcCoSePvQvN
		write_horizontal q_L_clarity 				"Articulation Index" 														RcCoSePvQvN
		
	table_end "$endline_all_LASSO" endline_all_LASSO
	
	* Appendix B12: Combined no covar
	table_start_horizontal endline_all_no_covar.txt ///
	"Endline Assessment Outcomes without Additional Covariates" 300 6 CM Sit-D SE p-value q-value N r r r p{1.2cm} p{1.1cm} r
	midrule
	
		write_horizontal q_N_knowledge 				"Knowledge Of Sit-D Concepts Index" 									RcCoSePvQvN
		write_horizontal q_N_assailants_correct 	"Correct assailant level in policy (index)"								RcCoSePvQvN
		write_horizontal q_N_force_correct 			"Correct force level in policy (index)" 								RcCoSePvQvN
		write_horizontal q_N_z_q50_level 			"Characterization of assailant who is a direct threat (z-score)" 		RcCoSePvQvN
		midrule
		write_horizontal q_N_total_interpretations "Total explanations" 													CmCoSePvQvN
		write_horizontal q_N_dummy_twocategories 	"Explanations from multiple categories" 								CmCoSePvQvN
		write_horizontal q_N_dummy_A 				"At least one explanation - assistance category" 						CmCoSePvQvN
		write_horizontal q_N_dummy_E 				"At least one explanation - enforcement category" 						CmCoSePvQvN
		write_horizontal q_N_dummy_NA 				"At least one explanation - other category" 							CmCoSePvQvN
		write_horizontal q_N_zall_features_unsel	"Alternative Features Index (both tasks)" 								RcCoSePvQvN
		write_horizontal q_N_zall_features_sel		"Confirming Features Index (both tasks)" 								RcCoSePvQvN
		write_horizontal q_N_overall 				"Criminal Interpretations Index (both tasks)" 							RcCoSePvQvN
		write_horizontal q_N_t_overall 				"Decision Time Index (both tasks)"  									RcCoSePvQvN
		write_horizontal q_N_proccessing_log_time 	"Processing Time Index (officer-timed task)"							RcCoSePvQvN
		write_horizontal q_N_appropriate_action2 	"Change - perceived threat \& force assessment (index)"					RcCoSePvQvN
		write_horizontal q_N_z_appropriate 			"Appropriate actions (index)" 											RcCoSePvQvN
		write_horizontal q_N_z_nonappropriate 		"Inappropriate actions (index)"											RcCoSePvQvN
		write_horizontal q_N_personalization 		"Personalization Index" 												RcCoSePvQvN
		write_horizontal q_N_stress					"Coping With Stress Index" 												RcCoSePvQvN	
		write_horizontal q_N_emotion 				"Emotion Regulation Index"												RcCoSePvQvN
		write_horizontal q_N_policing 				"Confidence Index"														RcCoSePvQvN
		midrule
		write_horizontal q_N_communicate 			"Did the officer communicate with the person? (index)" 					RcCoSePvQvN
		write_horizontal q_N_verbalize 				"Did the officer give verbal direction/ commands to the person? (index)" RcCoSePvQvN
		write_horizontal q_N_radio 					"Did the officer radio dispatch? (index)" 								RcCoSePvQvN
		write_horizontal q_N_freeze 				"Did the officer freeze during the scenario? (index)"					RcCoSePvQvN
		write_horizontal q_N_moving_cover 			"Did the officer kneel or move to cover/ concealment? (index)" 			RcCoSePvQvN
		write_horizontal q_N_shooting_FOS 			"Shooting in the FOS (interaction term)"								RcCoSePvQvN
		write_horizontal q_N_item					"Recall Index" 															RcCoSePvQvN
		write_horizontal q_N_clarity 				"Articulation Index" 													RcCoSePvQvN
		
	table_end "$endline_all_no_covar" endline_all_no_covar
	
	* Appendix B20: Combined - for experience
	mat hHshooting_FOS_t  = hH_shooting_FOS_treatment_risk
	mat hHshooting_FOS_te = hH_shooting_FOS_tre
	
	table_start_het_Experience endline_combined_het_Exp.txt ///
	"Effects on Endline Assessment Outcomes by Officer Experience" 
	midrule
		write_h hH_knowledge 				"Knowledge Of Sit-D Concepts Index" 									hidecm
		write_h hH_assailants_correct 		"Correct assailant level in policy (index)"								hidecm
		write_h hH_force_correct 			"Correct force level in policy (index)" 								hidecm
		write_h hH_z_q50_level 				"Characterization of assailant who is a direct threat (z-score)" 		hidecm
		midrule
		write_h hH_total_interpretations 	"Total explanations" 													
		write_h hH_dummy_twocategories 		"Explanations from multiple categories" 								
		write_h hH_dummy_A 					"At least one explanation - assistance category" 						
		write_h hH_dummy_E 					"At least one explanation - enforcement category" 						
		write_h hH_dummy_NA 				"At least one explanation - other category" 							
		write_h hH_zall_features_unsel		"Alternative Features Index (both tasks)" 								hidecm
		write_h hH_zall_features_sel		"Confirming Features Index (both tasks)" 								hidecm
		write_h hH_overall 					"Criminal Interpretations Index (both tasks)" 							hidecm
		write_h hH_t_overall 				"Decision Time Index (both tasks)"  									hidecm
		write_h hH_proccessing_log_time 	"Processing Time Index (officer-timed task)"							hidecm
		write_h hH_appropriate_action2 		"Change - perceived threat \& force assessment (index)"					hidecm
		write_h hH_z_appropriate 			"Appropriate actions (index)" 											hidecm
		write_h hH_z_nonappropriate 		"Inappropriate actions (index)"											hidecm
		write_h hH_personalization 			"Personalization Index" 												hidecm
		write_h hH_stress					"Coping With Stress Index" 												hidecm	
		write_h hH_emotion 					"Emotion Regulation Index"												hidecm
		write_h hH_policing 				"Confidence Index"														hidecm
		midrule
		write_h hH_communicate 				"Did the officer communicate with the person? (index)" 					 hidecm
		write_h hH_verbalize 				"Did the officer give verbal direction/ commands to the person? (index)" hidecm
		write_h hH_radio 					"Did the officer radio dispatch? (index)" 								hidecm
		write_h hH_freeze 					"Did the officer freeze during the scenario? (index)"					hidecm
		write_h hH_moving_cover 			"Did the officer kneel or move to cover/ concealment? (index)" 			hidecm
		write_h hH_item						"Recall Index" 															hidecm
		write_h hH_clarity 					"Articulation Index" 													hidecm
		midrule
		file write table ///
		"& \multicolumn{3}{c}{\begin{tabular}[c]{c@{}c@{}} \textbf{Sit-D $ \times $} \\ \textbf{Direct Threat} \end{tabular} } &  & \multicolumn{3}{c}{\begin{tabular}[c]{c@{}c@{}c@{}} \textbf{Sit-D $ \times $} \\ \textbf{Direct Threat $\times$} \\ \textbf{Experience} \end{tabular} } & &  \\ " _n ///
		"\hhline{ ~===~===~~} \\" _n

		write_h hHshooting_FOS	 			"Shooting in the FOS (interaction term)"							hidecm
	
	table_end "$endline_combined_het_Exp" endline_combined_het_Exp
	